package structures;

import structures.LinkedList.LinkedNode;

public class LinkReverse {

    public static void main(String[] args) {
        LinkedNode<Integer> head = new LinkedNode<>(0, "header1");
        LinkedNode<Integer> n1 = new LinkedNode<>(1, "n1");
        LinkedNode<Integer> n2 = new LinkedNode<>(2, "n2");
        LinkedNode<Integer> n3 = new LinkedNode<>(3, "n3");
        LinkedNode<Integer> n4 = new LinkedNode<>(4, "n4");
        LinkedNode<Integer> n5 = new LinkedNode<>(5, "n5");
        LinkedNode<Integer> n6 = new LinkedNode<>(6, "n6");
        LinkedNode<Integer> n7 = new LinkedNode<>(7, "n7");
        head.next = n1;
        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        n4.next = n5;
        n5.next = n6;
        n6.next = n7;
        n7.next = null;
        reverse(head);
        System.out.println(head);
    }


    public static <T> LinkedNode<T> reverse(LinkedNode<T> head) {

        LinkedNode<T> pre = null;
        LinkedNode<T> cur = head;

        while (cur != null) {
            LinkedNode<T> next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }

    public static <T> LinkedNode<T> middle(LinkedNode<T> head){
        return null;
    }
}
